//
//  KZMainViewController.m
//  zhuyuanbao
//
//  Created by Jason T on 15/10/20.
//  Copyright © 2015年 KangZhi. All rights reserved.
//

#import "KZMainVC.h"
#import "KZMineVC.h"
#import "KZNaviVC.h"
#import "KZTabBar.h"
#import "KZHosptialVC.h"
#import "KZCourseVC.h"
#import "KZhospitalTestVC.h"
#import "KZCourseTestVC.h"
#import "KZMineTestVC.h"

@interface KZMainVC ()<TabBarDelegate>
@property (nonatomic,strong)KZTabBar * mytabBar;

@end

@implementation KZMainVC



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        //添加子控制器
        
//        //住院
//        KZHosptialVC * hospitalVC = [[KZHosptialVC alloc]init];
//        hospitalVC.navigationItem.title = @"住院";
//        KZNaviVC * hosNaviVC = [[KZNaviVC alloc]initWithRootViewController:hospitalVC];
//        [self  addChildViewController:hosNaviVC];
//        [self.mytabBar addTabBarItem:hosNaviVC.tabBarItem withImageStr:@"zhuyuan_unseleted" selectedImageStr:@"zhuyuan"];
//        
//        
//        //课程
//        KZCourseVC * courseVC = [[KZCourseVC alloc]init];
//        courseVC.navigationItem.title = @"课程";
//        KZNaviVC * courseNaviVC = [[KZNaviVC alloc]initWithRootViewController:courseVC];
//        [self  addChildViewController:courseNaviVC];
//        [self.mytabBar addTabBarItem:courseNaviVC.tabBarItem withImageStr:@"kecheng_unseleted" selectedImageStr:@"kecheng"];
//        
//        
//        //我的
//        KZMineVC * mineVC = [[KZMineVC alloc]init];
//        mineVC.navigationItem.title = @"我的";
//        KZNaviVC * mineNaviVC = [[KZNaviVC alloc]initWithRootViewController:mineVC];
//        [self  addChildViewController:mineNaviVC];
//        [self.mytabBar addTabBarItem:mineVC.tabBarItem withImageStr:@"wode_unseleted" selectedImageStr:@"wode"];
        
        
//        住院
        KZhospitalTestVC * hospitalVC = [[KZhospitalTestVC alloc]init];
        hospitalVC.navigationItem.title = @"住院";
        KZNaviVC * hosNaviVC = [[KZNaviVC alloc]initWithRootViewController:hospitalVC];
        [self  addChildViewController:hosNaviVC];
        [self.mytabBar addTabBarItem:hosNaviVC.tabBarItem withImageStr:@"zhuyuan_unseleted" selectedImageStr:@"zhuyuan"];
        
        
        //课程
         KZCourseVC* courseVC = [[KZCourseVC alloc]init];
        courseVC.navigationItem.title = @"课程";
        KZNaviVC * courseNaviVC = [[KZNaviVC alloc]initWithRootViewController:courseVC];
        [self  addChildViewController:courseNaviVC];
        [self.mytabBar addTabBarItem:courseNaviVC.tabBarItem withImageStr:@"kecheng_unseleted" selectedImageStr:@"kecheng"];
        
        
        //我的
        KZMineTestVC * mineVC = [[KZMineTestVC alloc]init];
        mineVC.navigationItem.title = @"我的";
        KZNaviVC * mineNaviVC = [[KZNaviVC alloc]initWithRootViewController:mineVC];
        [self  addChildViewController:mineNaviVC];
        [self.mytabBar addTabBarItem:mineVC.tabBarItem withImageStr:@"wode_unseleted" selectedImageStr:@"wode"];
        
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 自定义tabBar
    [self addtabBar];

}


//布局子控件后移除系统多余的东西
- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    
    //2。移除tabBar自带的子控件
    for (UIView *item in self.tabBar.subviews) {
        
        if (![item isKindOfClass:[KZTabBar class]]) {
            [item removeFromSuperview];
            
        }
        //         NSLog(@"%@",item.subviews);
    }
    UILabel * dividerLine = [[UILabel alloc]initWithFrame:CGRectMake(0, -1, screenWidth, 0.5)];
    dividerLine.backgroundColor = KZColor(212, 212, 212);
    [self.tabBar addSubview:dividerLine];
}



- (void)addtabBar
{
    //1。自定义tabBar
    KZTabBar * myTabBar = [[KZTabBar alloc]init];
    myTabBar.frame =self.tabBar.bounds;
    
    self.mytabBar = myTabBar;
    
    
    //设置代理
    myTabBar.delegate = self;
    
    
    //3 。添加myTabBar到系统的tabBar
    [self.tabBar addSubview:myTabBar];
    
    
}
#pragma mark - TabBarDelegate

- (void)KZTabBar:(KZTabBar *)tabBar swithfrom:(NSUInteger)from to:(NSUInteger)to
{
        self.selectedIndex = to;
}


@end
